<?php
include '../config.php';
// Connecting, selecting database

$mysqli = new mysqli($MYSQL_HOST, $MYSQL_USERNAME, $MYSQL_PASSWORD, $MYSQL_DB_NAME);
if ($mysqli->connect_errno) {
	echo "Failed to connect to MySQL: " . $mysqli->connect_error;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF8">
<title>Open Badges - Pagina Badge Utente </title> 
</head>
<body>
	<h1>Open Badges - Elenco Badges</h1>
	<div>
	<p>Vengono qui presentate le badge assegnate a 
		<?php $array = preg_split("/#/", $_POST["user"]);
		$earner_id = $array[0];
		$earner_email = $array[1]; 
		echo $earner_email; ?></p>
	</div>
	<?php 
		$query = "SELECT badge.immagine, issuer.nome FROM baked_badge INNER JOIN badge ON bakedBadge=badgeId INNER JOIN issuer on issuerId=idIssuer WHERE bakedUser='" . $earner_id ."'";
		$result = $mysqli->query($query) or die('Query failed: ' . mysql_error());
		$path="../../";
		while($row=$result->fetch_assoc()){
			echo "La badge è stata rilasciata da: " . $row['nome'];
			echo "<div>";
			echo "<img src=\"" . $path . $row['immagine'] . "\">";
			echo "</div>";
		}
			// Free result set
			$result->close();
		
			// Closing connection
			$mysqli->close();
	?>

<div>
	<p><a href="../../displayer.php">Indietro</a></p>
</div>
<div>
	<p>Torna alla <a href="../../index.html">Home</a></p>
</div>
</body>
</html>